//
//  MyTabBarController.m
//  MobiProject
//
//  Created by 阔 李 on 15-3-27.
//  Copyright (c) 2015年 阔 李. All rights reserved.
//

#import "MyTabBarController.h"
#import "CrowdfundingViewController.h"
#import "MoreViewController.h"
#import "HomeRootViewController.h"


@interface MyTabBarController ()

@end

@implementation MyTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.delegate =self;
    
    
    HomeRootViewController *controller1=[[HomeRootViewController alloc] init];
    controller1.view.backgroundColor = [UIColor whiteColor];
    UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:controller1];
   
    CrowdfundingViewController *controller2=[[CrowdfundingViewController alloc] init];
    controller2.view.backgroundColor = [UIColor blackColor];
    UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:controller2];
    
    MoreViewController *controller3=[[MoreViewController alloc] init];
    controller3.view.backgroundColor =[UIColor whiteColor];
    UINavigationController *nav3 = [[UINavigationController alloc] initWithRootViewController:controller3];

    NSArray *controllers=[[NSArray alloc] initWithObjects: nav1, nav2, nav3, nil];
    
    
    self.viewControllers=controllers;
    
    for (int i=0; i<self.tabBar.items.count;i++) {
        
        // 正常图片
        NSString *strNormal;
        
        // 选中图片
        NSString *strSelect;
        
        strNormal=[NSString stringWithFormat:@"page%d_normal", i+1];
        strSelect=[NSString stringWithFormat:@"page%d_select", i+1];
        UIImage * image = [[UIImage alloc] init];
        UIImage * selectImage = [[UIImage alloc] init];
        selectImage = [UIImage imageNamed:strNormal];
        image = [UIImage imageNamed:strSelect];
        
        NSString * title = @"";
        
        UITabBarItem*item=self.tabBar.items[i];
        item.imageInsets = UIEdgeInsetsMake(0, 0, 0, 0);
        if (i==0) {
            title=@"首页";
        }
        else if(i==1){
            title=@"众筹";
        }
        else if(i==2){
            title=@"我的";

        }
        

        
        if ([PublicFunction isIOS7OrLater]) {
            [item setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[ZJCModel colorWithString:@"999999"], NSForegroundColorAttributeName, nil] forState:UIControlStateNormal];
            
            [item setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[ZJCModel colorWithString:@"12c0f8"], NSForegroundColorAttributeName, nil] forState:UIControlStateSelected];
            item.title = title;
            [item setSelectedImage:[image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
            [item setImage:[selectImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
        }else {
            [item setFinishedSelectedImage:image withFinishedUnselectedImage:selectImage];
        }
    }
}
#pragma mark - UITabBarControllerDelegate
-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    NSLog(@"========%lu",tabBarController.selectedIndex);
    // 
    //[self.selectedViewController.navigationController popToRootViewControllerAnimated:NO];
}
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
    return YES;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
